package com.tomato.thread.pool;

import java.text.MessageFormat;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static java.text.MessageFormat.*;

/**
 * 自定义线程池
 */
public class CustomThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor executor =
                new ThreadPoolExecutor(
                        2,
                        10,
                        0,
                        TimeUnit.SECONDS,
                        new LinkedBlockingDeque<>(20));
        for(int i = 0; i < 30; i++) {
            executor.execute(() -> {
                System.out.println(format("{0}执行任务",Thread.currentThread().getName()));
            });
        }
    }
}
